// pages/my/mypage/rechargeB/rechargeB.js
const app = getApp()
const $ = app.globalData
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		chongzhi: [{
				money: "50",
				shoujia: "5"
			},
			{
				money: "100",
				shoujia: "10"
			},
			{
				money: "200",
				shoujia: "20"
			},
			{
				money: "300",
				shoujia: "30"
			},
			{
				money: "500",
				shoujia: "50"
			},
			{
				money: "1000",
				shoujia: "100"
			}
		],
		cliindex: 0,
		xuanzeico: "https://www.yoyuegoo.com/static/yoyuegooImg/duixuanze.png",
		thisstatr: true,
		symoney:""
	},
	chongzhi: function(e) {
		console.log(e.currentTarget.dataset.index)
		this.setData({
			cliindex: e.currentTarget.dataset.index,
			symoney:""
		})
	},
	xuanzeico: function(e) {
		var thisstatra = e.currentTarget.dataset.statr
		thisstatra = !thisstatra
		if (thisstatra) {
			this.setData({
				xuanzeico: "https://www.yoyuegoo.com/static/yoyuegooImg/duixuanze.png"
			})
		} else {
			this.setData({
				xuanzeico: "https://www.yoyuegoo.com/static/yoyuegooImg/duiweixuanz.png"
			})
		}
		this.setData({
			thisstatr: thisstatra
		})
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {

	},
	symoney:function(e){
		var that = this
		that.setData({
			symoney:e.detail.value,
			cliindex:6
		})
	},
	// 充值
	chongzhibut: function() {
		var that = this
		var ind = that.data.cliindex
		var money = 0
		if(ind != 6){
			money = that.data.chongzhi[ind].money
		}
		money = that.data.symoney?that.data.symoney:money
		wx.getStorage({
			key: "userinfo",
			success: function(data) {
				wx.request({
					url: $.AdminUrl + "/YApi/createRechargeOrder",
					data: {
						customerid: data.data.id,
						cashmoney: money,
						integralmoney: 0,
						rechargetype: 0,
						remark: "",
						openid: wx.getStorageSync("openid")
					},
					success: (res) => {
							wx.requestPayment({
								timeStamp:res.data.timeStamp, //记住，这边的timeStamp一定要是字符串类型的，不然会报错
								nonceStr:res.data.nonceStr,
								package:res.data.package,
								signType: 'MD5',
								paySign:res.data.paySign,
								success: function(event) {
									console.log(event);
								},
							})
						console.log(res)
					}
				})
			}
		})
	},
	// 分享转发
		onShareAppMessage: function() {
			var userinfo = wx.getStorageSync('userinfo')
			return {
				title: '优悦购生活管家',
				path: '/pages/index/index?userid='+userinfo.loginname,
				success: (res) => {
					console.log("转发成功", res);
				},
				fail: (res) => {
					console.log("转发失败", res);
				}
			}
		}
})
